package com.langsotech.studio.action.diagram4gef.figures;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import com.langsotech.studio.action.diagram4gef.Activator;
public class TransformationFigure extends RoundedRectangle {
	static final Color BG = new Color(null, 242, 240, 255);
	String path = "icons/file.gif";
	/*static Image classImage = new Image(null,
			UMLClassFigure.class.getResourceAsStream("class_obj.gif"));*/
	public Image getImage() {
		Image image = JFaceResources.getImageRegistry().get(path);
		if (image == null) {
			ImageDescriptor descriptor = AbstractUIPlugin
					.imageDescriptorFromPlugin(
							Activator.PLUGIN_ID, path); 
			if (descriptor == null) {
				descriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			JFaceResources.getImageRegistry().put(path,
					image = descriptor.createImage());
		}
		return image;
	}
	static Font BOLD = new Font(null, "", 10, SWT.BOLD);
	public TransformationFigure() {
		class SeparatorBorder extends MarginBorder {
			SeparatorBorder() {
				super(3, 5, 3, 5);
			}
			public void paint(IFigure figure, Graphics graphics, Insets insets) {
				Rectangle where = getPaintRectangle(figure, insets);
				graphics.drawLine(where.getTopLeft(), where.getTopRight());
			}
		}
		this.setCornerDimensions(new Dimension(20, 20));
		Label header = new Label("ClassName", getImage());
		header.setFont(BOLD);
		header.setBorder(new MarginBorder(3, 5, 3, 5));
		Figure attributes = new Figure();
		ToolbarLayout layout;
		attributes.setLayoutManager(layout = new ToolbarLayout());
		layout.setStretchMinorAxis(false);
		attributes.add(new Label("name : String"));
		attributes.add(new Label("ID : String"));
		attributes.setBorder(new SeparatorBorder());
		Figure methods = new Figure();
		methods.setLayoutManager(layout = new ToolbarLayout());
		layout.setStretchMinorAxis(false);
		methods.add(new Label("foo() : int"));
		methods.add(new Label("bar() : char"));
		methods.setBorder(new SeparatorBorder());
		setLayoutManager(new ToolbarLayout());
		add(header);
		add(attributes);
		add(methods);
		setOpaque(true);
		setBackgroundColor(BG);
	}
}
